using System;

namespace Tort.Attributes
{
    /// <summary>
    /// Defines load &amp; save parameters for complex objects
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public sealed class LoadRequirementAttribute : DBFieldAttribute
    {
        /// <summary>
        /// Default load parameter, lazy (when required), and one to one relationship
        /// </summary>
        public LoadRequirementAttribute() 
        {
            LoadRequirement(LoadProperty.Lazy, LoadTypeProperty.OneToOne);
        }

        /// <summary>
        /// Defines one to one, one to many, many to many mapping. Lazy Loading default
        /// </summary>
        /// <param name="dbProperty"></param>
        public LoadRequirementAttribute(LoadTypeProperty typeProperty) 
        {
            LoadRequirement(LoadProperty.Lazy, typeProperty);
        }

        /// <summary>
        /// Defines one to one, one to many, many to many mapping. Specified loading 
        /// </summary>
        /// <param name="loadProperty"></param>
        /// <param name="dbProperty"></param>
        public LoadRequirementAttribute(LoadProperty loadProperty, LoadTypeProperty typeProperty) 
        {
            LoadRequirement(loadProperty, typeProperty);
        }

        /// <summary>
        /// Allows the setting of a specific column to bind the complex object to (pk - fk relationship typically
        /// </summary>
        /// <param name="columnName"></param>
        public LoadRequirementAttribute(String columnName) 
            : base (columnName)
        {
            LoadRequirement(LoadProperty.Lazy, LoadTypeProperty.OneToOne);
        }

        private LoadProperty loadPropertyData;
        private LoadTypeProperty typePropertyData;

        private void LoadRequirement(LoadProperty loadProperty, LoadTypeProperty typeProperty)
        {
            loadPropertyData = loadProperty;
            typePropertyData = typeProperty;
        }

        public LoadProperty Property { get { return loadPropertyData; } }
        public LoadTypeProperty TypeProperty { get { return typePropertyData; } }
    }
}
